package org.dochandler.service.core;

import org.dochandler.dao.DAO;
import org.dochandler.dao.OfficerDAO;
import org.dochandler.service.LoginService;
import org.dochandler.service.domain.Officer;
import org.dochandler.service.exception.AuthenticationException;
import org.esfinge.guardian.utils.ServiceLocator;

@SuppressWarnings("serial")
public class LoginServiceCore implements LoginService {
	private DAO<Officer> officerDao;
	
	public LoginServiceCore() {
		setOfficerDao( ServiceLocator.getServiceImplementation(OfficerDAO.class) );
	}
	
	public Officer login(Long officerId, String pwd) throws AuthenticationException {
		Officer officer = getOfficerDao().findById(officerId);
		
		if (officer != null && pwd.equals(officer.getPassword())) {
			return officer;
		}
		
		throw new AuthenticationException("Can't authenticate Officer: " + officerId);
	}
	
	/* SETTERS AND GETTERS */
	
	public DAO<Officer> getOfficerDao() {
		return officerDao;
	}
	
	public void setOfficerDao(DAO<Officer> officerDao) {
		this.officerDao = officerDao;
	}
}